package com.ble.utlis;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

/**
 * 记录用户名，密码之类的首选项
 */
public class PreferenceUtil {
    private static PreferenceUtil preference = null;
    private SharedPreferences sharedPreference;
    private String packageName = "";

    public static final String JOBNUMBER = "JobNumber"; // 登录手机号
    public static final String BARCODE = "barcode"; // 登录手机号
    public static final String MAC = "MAC"; // 登录手机号
    public static final String NAME = "NAME"; // 登录手机号
    public static final String MODE = "MODE"; // 登录手机号
    public static final String adress = "adress"; // 登录手机号
    public String getAdress(String defValue) {
        String value = sharedPreference.getString(adress,defValue);
        return value;
    }

    public void setAdress(String value) {
        Editor edit = sharedPreference.edit();
        edit.putString(adress, value);
        edit.commit();
    }


    public static synchronized PreferenceUtil getInstance(Context context) {
        if (preference == null)
            preference = new PreferenceUtil(context);
        return preference;
    }

    public PreferenceUtil(Context context) {
        packageName = context.getPackageName() + "_preferences";
        sharedPreference = context.getSharedPreferences(packageName,
                Context.MODE_PRIVATE);
    }

    public String getJobNumber(String defValue) {
        String value = sharedPreference.getString(JOBNUMBER, defValue);
        return value;
    }

    public void setJobNumber(String value) {
        Editor edit = sharedPreference.edit();
        edit.putString(JOBNUMBER, value);
        edit.commit();
    }

    public String getBarcode(String defValue) {
        String value = sharedPreference.getString(BARCODE, defValue);
        return value;
    }

    public void setBarcode(String value) {
        Editor edit = sharedPreference.edit();
        edit.putString(BARCODE, value);
        edit.commit();
    }

    public String getMac(String defValue) {
        String value = sharedPreference.getString(MAC, defValue);
        return value;
    }

    public void setMac(String value) {
        Editor edit = sharedPreference.edit();
        edit.putString(MAC, value);
        edit.commit();
    }

    public String getName(String defValue) {
        String value = sharedPreference.getString(NAME, defValue);
        return value;
    }

    public void setName(String value) {
        Editor edit = sharedPreference.edit();
        edit.putString(NAME, value);
        edit.commit();
    }

    public String getMode(String defValue) {
        String value = sharedPreference.getString(MODE, defValue);
        return value;
    }

    public void setMode(String value) {
        Editor edit = sharedPreference.edit();
        edit.putString(MODE, value);
        edit.commit();
    }

}
